package com.purchase.order.service.Impl;

import com.purchase.common.utils.uuid.IdUtils;
import com.purchase.order.domain.OrderCompanyType;
import com.purchase.order.mapper.CompanyTypeMapper;
import com.purchase.order.service.ICompanyTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author oyi46
 * @version 1.0
 * Create by 2023/7/24 9:34
 */

@Service
public class CompanyTypeServiceImpl implements ICompanyTypeService {

    @Autowired
    CompanyTypeMapper companyTypeMapper;

    //添加公司种类
    @Override
    public void insertType(Long typeId,String name) {
        if ( companyTypeMapper.checkName(name) !=0){
            throw new SecurityException("该类别已存在");
        }
        Long materialId = IdUtils.randomSnowflake();
        if (companyTypeMapper.insertTye(materialId,typeId,name) !=1){
            throw new SecurityException("添加类别失败");
        }
    }

    //删除公司种类
    @Override
    public void deleteType(Long materialId) {
        if (companyTypeMapper.deleteType(materialId) !=1){
            throw new SecurityException("删除公司类别失败");
        }
    }

    //获取子类的列表
    @Override
    public List<OrderCompanyType> typeList(Long typeId) {
        return companyTypeMapper.typeList(typeId);
    }

    @Override
    public List<OrderCompanyType> getall() {
        return companyTypeMapper.getall();
    }
}
